using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class PackagerAndroid : PackagerBase
{
    public override void BuildPlayer(bool export = true)
    {
        BuildAssetBundle();
        if (export)
            ExportGradleProj();
        else
            CreateApk();
    }

    private void CreateApk()
    {
        string[] levels = packagerRules.startupScenes;
        string packagePath = $"{PreparePackageDir()}/{packagerRules.appName}{GetAppExtension()}";

        BuildPipeline.BuildPlayer(
            levels,
            packagePath,
            BuildTarget.Android,
            Packager.DEVELOPMENT ? BuildOptions.Development | BuildOptions.ConnectWithProfiler : BuildOptions.None);
    }

    private void ExportGradleProj()
    {
        string[] levels = packagerRules.startupScenes;
        string packagePath = PreparePackageDir();

        EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
        EditorUserBuildSettings.development = Packager.DEVELOPMENT;
        EditorUserBuildSettings.connectProfiler = Packager.DEVELOPMENT;
        BuildPipeline.BuildPlayer(
            levels,
            packagePath,
            BuildTarget.Android,
            Packager.DEVELOPMENT
                ? BuildOptions.Development | 
                  BuildOptions.ConnectWithProfiler |
                  BuildOptions.AcceptExternalModificationsToPlayer
                : BuildOptions.AcceptExternalModificationsToPlayer);
    }
}
